package com.qianxing.controller;

import com.qianxing.dto.TravelDataDTO;
import com.qianxing.exceptionhandler.ResponseException;
import com.qianxing.service.TbTravelDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @Author:JasonLong
 * @Date:2023/7/11
 * @Time:9:58
 */
@RestController
@RequestMapping("/travel")
public class WxTravelDataController {

    @Autowired
    private TbTravelDataService tbTravelDataService;

    @GetMapping("/getTravel")
    public List getTravel() {
        return tbTravelDataService.getTravel();
    }

    /**
     * 添加事务操作，维护数据一致性
     *
     * @param files
     * @return
     */
    @RequestMapping("/uploadFile")
    public ResponseException saveTravelFile(@RequestParam("token") String token,
                                            @RequestParam("travelId") String travelId,
                                            @RequestParam("travelTitle") String travelTitle,
                                            @RequestParam("travelMsg") String travelMsg,
                                            @RequestParam("files") MultipartFile files) {
        System.out.println("传到后台:");
        System.out.println(travelId);
        System.out.println(files.getOriginalFilename());
        ResponseException responseException = tbTravelDataService.saveTravelFile(travelId,travelTitle,travelMsg, token, files);
        return responseException;
    }

    @RequestMapping("/getTravelId")
    public String getTravelId() {
        return tbTravelDataService.getTravelId();
    }
}
